package com.charlie.beans;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Вова
 */
@Entity
@Table(name = "SO_PRODUCT")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "SoProduct.findAll", query = "SELECT s FROM SoProduct s"),
    @NamedQuery(name = "SoProduct.findByProductSoId", query = "SELECT s FROM SoProduct s WHERE s.productSoId = :productSoId"),
    @NamedQuery(name = "SoProduct.findByAmount", query = "SELECT s FROM SoProduct s WHERE s.amount = :amount")})
public class SoProduct implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @SequenceGenerator(name = "SO_PRODUCT_SEQ", sequenceName = "SO_PRODUCT_PRODUCT_SO_ID_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SO_PRODUCT_SEQ")   
    @Column(name = "PRODUCT_SO_ID")
    private Integer productSoId;
    @Basic(optional = false)
    @NotNull
    @Column(name = "AMOUNT")
    private int amount;
    @JoinColumn(name = "SO_ID", referencedColumnName = "SO_ID")
    @ManyToOne(optional = false)
    private ShipmentOrder soId;
    @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "PRODUCT_ID")
    @ManyToOne(optional = false)
    private Product productId;

    public SoProduct() {
    }

    public SoProduct(Integer productSoId) {
        this.productSoId = productSoId;
    }

    public SoProduct(Integer productSoId, int amount) {
        this.productSoId = productSoId;
        this.amount = amount;
    }

    public Integer getProductSoId() {
        return productSoId;
    }

    public void setProductSoId(Integer productSoId) {
        this.productSoId = productSoId;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public ShipmentOrder getSoId() {
        return soId;
    }

    public void setSoId(ShipmentOrder soId) {
        this.soId = soId;
    }

    public Product getProductId() {
        return productId;
    }

    public void setProductId(Product productId) {
        this.productId = productId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productSoId != null ? productSoId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SoProduct)) {
            return false;
        }
        SoProduct other = (SoProduct) object;
        if ((this.productSoId == null && other.productSoId != null) || (this.productSoId != null && !this.productSoId.equals(other.productSoId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.charlie.beans.SoProduct[ productSoId=" + productSoId
                + ", productId=" + productId.getProductId()
                + ", amount=" + amount + " ]";
    }
    
}
